import request from '@/utils/request'

// 查询补贴政策列表
export function listPolicy(query) {
  return request({
    url: '/yjnb/policy/page',
    method: 'get',
    params: query
  })
}

// 查询补贴政策详细
export function getPolicy(id) {
  return request({
    url: '/yjnb/policy/' + id,
    method: 'get'
  })
}

// 新增补贴政策
export function addPolicy(data) {
  return request({
    url: '/yjnb/policy/add',
    method: 'post',
    data: data
  })
}

// 修改补贴政策
export function updatePolicy(data) {
  return request({
    url: '/yjnb/policy/update',
    method: 'put',
    data: data
  })
}

// 删除补贴政策（单个或批量）
export function delPolicy(ids) {
  // 如果是数组，转换为逗号分隔的字符串
  const idString = Array.isArray(ids) ? ids.join(',') : ids;
  return request({
    url: '/yjnb/policy/delete/' + idString,
    method: 'delete'
  })
}

// 单个修改发布状态
export function updatePolicyStatus(id, status) {
  return request({
    url: '/yjnb/policy/updateStatus',
    method: 'put',
    params: { id, status }
  })
}

// 单个修改推荐状态
export function updatePolicyRecommend(id, isRecommend) {
  return request({
    url: '/yjnb/policy/updateRecommend',
    method: 'put',
    params: { id, isRecommend }
  })
}
export function releaseAllowancePolicy(data) {
  return request({
    url:"/yjnb/policy/releaseAllowancePolicy",
    method: "post",
    data: data,
    withLoading: true,
  });
}
// 取消发布
export function unreleaseAllowancePolicy(data) {
  return request({
    url:"/yjnb/policy/unreleaseAllowancePolicy",
    method: "post",
    data: data,
    withLoading: true,
  });
}
// 推荐
export function recommendAllowancePolicy(data) {
  return request({
    url:"/yjnb/policy/recommendAllowancePolicy",
    method: "post",
    data: data,
    withLoading: true,
  });
}
// 取消推荐
export function unrecommendAllowancePolicy(data) {
  return request({
    url:"/yjnb/policy/unrecommendAllowancePolicy",
        method: "post",
    data: data,
    withLoading: true,
  });
}


// 导出补贴政策数据
export function exportPolicy() {
  return request({
    url: '/common/excel/allowancePolicy/export',
    method: 'get',
    responseType: 'blob',
    withLoading: true
  })
}
